package com.muqi.app.pj.shops;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.qlearn.student.R;

public class OrderGoodsAdapter extends BaseAdapter {
	private List<OrderDetailBean> mDataList;
	private Context mContext;
	private int parrentPos;
	private int type;

	public OrderGoodsAdapter(Context context, List<OrderDetailBean> data,
			int type, int parrentPos) {
		mContext = context;
		mDataList = data;
		this.type = type;
		this.parrentPos = parrentPos;
	}

	@Override
	public int getCount() {
		return mDataList == null ? 0 : mDataList.size();
	}

	@Override
	public Object getItem(int position) {
		if (mDataList == null || position >= mDataList.size())
			return null;
		return mDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		OrderDetailBean data = mDataList.get(position);
		ViewHolder holder = null;
		if (null == convertView) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_mine_order_inner, null);
			holder.icon = (ImageView) convertView
					.findViewById(R.id.shopcar_goods_pic);
			holder.goodsName = (TextView) convertView
					.findViewById(R.id.shopcar_goods_name);
			holder.price = (TextView) convertView
					.findViewById(R.id.shopcar_goods_price);
			holder.count = (TextView) convertView
					.findViewById(R.id.shopcar_goods_num);
			holder.backGoods = (TextView) convertView
					.findViewById(R.id.back_goods);
			holder.backGoodsIng = (TextView) convertView
					.findViewById(R.id.back_goods_going);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (data.getShangpin_xq().fileurl != null) {
			GlideImageUtils.setImageLoader(mContext,
					data.getShangpin_xq().fileurl.fileurl_02, holder.icon,
					R.drawable.app_logo);
		}

		if (data.getShangpin_xq().mingcheng != null
				&& !data.getShangpin_xq().mingcheng.equals("")) {
			holder.goodsName.setText(data.getShangpin_xq().mingcheng);
			holder.price.setText("￥" + (int) data.getShangpin_xq().danjia);
		} else {
			holder.goodsName.setText(data.getShangpin_xq().title);
			holder.price.setText("￥" + data.getShangpin_xq().credits);
		}
		
		

		

		holder.backGoods.setTag(data);
		holder.backGoods.setVisibility(View.GONE);
		holder.count.setVisibility(View.VISIBLE);
		holder.count.setText("数量" + data.getShuliang() + "");
		/*
		 * if (type == -1) { holder.backGoods.setVisibility(View.GONE);
		 * holder.count.setVisibility(View.VISIBLE); holder.count.setText("数量" +
		 * data.getShuliang() + ""); } else {
		 * holder.count.setVisibility(View.GONE);
		 * 
		 * if (type != 1 && data.getShangpin_xq().zhichituihuo.equals("1")) {//
		 * 已付款且支持退货 if (data.getTuihuo_zhuangtai().equals("1")) {
		 * holder.backGoods.setVisibility(View.GONE);
		 * holder.backGoodsIng.setVisibility(View.VISIBLE); } else {
		 * holder.backGoods.setVisibility(View.VISIBLE);
		 * holder.backGoodsIng.setVisibility(View.GONE); } } else {
		 * holder.backGoods.setVisibility(View.GONE);
		 * holder.backGoodsIng.setVisibility(View.GONE); }
		 * 
		 * }
		 */
		return convertView;
	}

	class ViewHolder {
		ImageView icon;
		TextView goodsName;
		TextView price;
		TextView count;
		TextView backGoods;
		TextView backGoodsIng;
	}

}
